﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Forms;

namespace MiniGOQO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            CameraCaptureDialog ccd = new CameraCaptureDialog();
            ccd.Owner = this;
            ccd.Resolution = new Size(80, 100);

            try
            {
                // Displays the "Camera Capture" dialog box
                if (DialogResult.OK == ccd.ShowDialog())
                {
                    string fileName = ccd.FileName;

                    // If it is a video we rename the file so that it has the user entered
                    // default filename and the correct extension.
                    if (ccd.Mode != CameraCaptureMode.Still)
                    {
                        string extension = fileName.Substring(fileName.LastIndexOf("."));
                        string directory = "";

                        if (fileName.LastIndexOf("\\") != -1)
                        {
                            directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1);
                        }

                        fileName = directory  + extension;

                        System.IO.File.Move(ccd.FileName, fileName);
                    }

                    // The method completed successfully.
                    MessageBox.Show("相片或录像已成功获取并保存于:\n\n" + fileName,
                        this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);

                    SelectPictureDialog spd = new SelectPictureDialog();
                    if (spd.ShowDialog() == DialogResult.OK)
                    {
                        //sourceName = spd.FileName;
                       // pictureBoxMap.Image = new System.Drawing.Bitmap(spd.FileName);
                        //menuItem7.Enabled = true;
                    }
                }
            }
            catch (ArgumentException ex)
            {
                // An invalid argument was specified.
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            catch (OutOfMemoryException ex)
            {
                // There is not enough memory to save the image or video.
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                    MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            catch (InvalidOperationException ex)
            {
                // An unknown error occurred.
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                    MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }
    }
}